create or replace function trigger_locations_insert() returns trigger as $$
declare
begin
-- insert into locations (loc_id, loc_name, lat, lon, geom) select loc_id, loc_name, lat, lon, ST_GeomFromText('POINT(' ||lon||' '||lat|| ')',4326) from (select NEW.*) as foo;*/
-- insert into locations (loc_id, loc_name, lat, lon, cresta_name) select loc_id, loc_name, lat, lon, 'test' from (select NEW.*) as foo;*/
-- UPDATE locations SET cresta_name = 'test' WHERE loc_id = 8546;
-- NEW.cresta_name = 'test';
NEW.geom = ST_GeomFromText('POINT(' ||NEW.lon||' '||NEW.lat|| ')',4326);
NEW.geog = NEW.geom::geography;
return NEW;
end;
$$
language 'plpgsql' volatile;

create trigger trigger_ece_before_insert before insert on locations for each row
execute procedure trigger_locations_insert();